<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>用户管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/resources/layui/css/layui.css"/>

</head>
<body>
<div style="padding: 20px 10px 0px">
    <fieldset class="layui-elem-field">
        <legend>查询条件</legend>
        <div class="layui-field-box">
            <form class="layui-form" action="" id="searchFrm">
                <div class="layui-form-item layui-input-inline">
                    <label class="layui-form-label">用户名称</label>
                    <div class="layui-input-inline">

                        <input type="hidden" name="loginname" readonly th:value="${session.user.loginname}" autocomplete="off"
                               class="layui-input">
                        <input type="text" name="name" readonly th:value="${session.user.name}" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-input-inline">
                    <label class="layui-form-label">原始密码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="pwd" required placeholder="请输入原始密码" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-input-inline">
                    <label class="layui-form-label">新的密码</label>
                    <div class="layui-input-inline">
                        <input type="text" id="newpwd" name="newpwd" required placeholder="请输入新的密码" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-input-inline">
                    <label class="layui-form-label">确认密码</label>
                    <div class="layui-input-inline">
                        <input type="text" name="againpwd" required lay-verify="repass" placeholder="请输入确认密码"
                               autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="text-align: center;">
                    <div class="layui-input-baddressk">
                        <button type="button" class="layui-btn" lay-submit="" lay-filter="doSubmit">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </fieldset>
</div>

<script src="/resources/layui/layui.js"></script>
<script>
    layui.use(['form','jquery','layer'],function () {
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;
        form.verify({
            repass: function (value) {
                //获取密码
                var pass = $("#newpwd").val();
                if (!(pass==value)) {
                    return '两次输入的密码不一致';
                }
            }

        });
        //监听提交密码修改事件
        form.on("submit(doSubmit)", function (data) {
            var params = $("#searchFrm").serialize();
            $.post("/user/updateUserPwd",params,function (obj) {
                // layer.msg(obj.msg);
                if(obj.code==200){
                    layer.confirm('密码修改成功 请重新登录', {icon: 1, title:'提示'}, function(index){
                        layer.close(index);
                        window.top.location.href="/index.html"
                    });
                }else {
                    layer.confirm(obj.msg, {icon: 2},function (index) {
                        layer.close(index);
                    });
                }
            })
        });
    });




</script>
</body>

</html>